﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace FinalWeb
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            txtNo.Focus();
            txtPwd.Focus();
            txtReP.Focus();
        }

        protected void btnRe_Click(object sender, EventArgs e)
        {

            this.txtNo.Text = "";
            this.txtPwd.Text = "";
            this.txtReP.Text = "";

        }

        protected void btnSure_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112102;uid=2014112102;pwd=19960523;";
            SqlConnection cn = new SqlConnection(strCn);

            try
            {
                cn.Open();
                StringBuilder SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("INSERT INTO UserInfo ");
                SqlStringBuilder.Append("                (UserName, Password) ");
                SqlStringBuilder.Append("VALUES   (@UserName,@Password) ");
                string Sql = SqlStringBuilder.ToString();
                SqlCommand cmd = new SqlCommand(Sql, cn);
                SqlParameter pmsUserName = new SqlParameter("@UserName", this.txtNo.Text);
                SqlParameter pmsPassword = new SqlParameter("@Password", this.txtPwd.Text);
                cmd.Parameters.Add(pmsUserName);
                cmd.Parameters.Add(pmsPassword);
                cmd.ExecuteNonQuery();

                int iAdd = cmd.ExecuteNonQuery();
                if (iAdd < 1)
                {
                    Response.Write(@"<script>alert('注册失败！');</script>"); 
                }
                else
                {
                    //Response.Write(" <script language=javascript>alert('注册成功');window.window.location.href='WebForm2.aspx';</script> ");
                    Response.Write(@"<script language=javascript>alert('注册成功！请进入个人中心补充资料');window.window.location.href='UserLogin.aspx';</script>"); 
                }
                string strSql = "INSERT INTO Members (Name, Tel) VALUES   (N'"+this.txtName.Text+"', N'"+this.txtTel.Text+"')";
                SqlCommand cd = new SqlCommand(strSql, cn);
                cd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                this.lblMes.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        protected void btnIn_Click(object sender, EventArgs e)
        {

        }
    }
}